<template>
  <div id="list">
    <!-- 面包屑导航区域 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item><a href="/home">首页</a></el-breadcrumb-item>
      <el-breadcrumb-item>商品管理</el-breadcrumb-item>
      <el-breadcrumb-item>商品列表</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- 卡片视图区域 -->
    <el-card>
      <el-row>
        <el-col :span="8">
          <el-input placeholder="请输入内容" v-model="searchValue">
            <template #append>
              <i class="el-icon-search"></i>
            </template>
          </el-input>
        </el-col>
        <el-col :span="5">
          <el-button type="primary" class="add-user-btn">添加用户</el-button>
        </el-col>
      </el-row>
      <el-table :data="goodsList">
        <el-table-column type="index" label="#"></el-table-column>
        <el-table-column label="商品名称" prop="goods_name"></el-table-column>
        <el-table-column label="商品价格(元)" prop="goods_price"></el-table-column>
        <el-table-column label="商品重量" prop="goods_weight"></el-table-column>
        <el-table-column label="商品名称" prop="add_time"></el-table-column>
        <el-table-column label="操作">
          <template v-slot:default="scope">
            {{scope.id }
            <el-button type="primary" icon="el-icon-edit"></el-button>
            <el-button type="danger" icon="el-icon-delete"></el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script>
export default {
  name: 'list',
  data() {
    return {
      // 查询关键字
      searchValue: '',
      // 商品列表
      goodsList: [],
      // 商品总数
      total: 0,
      queryInfo: {
        query: '',
        pagenum: 1,
        pagesize: 10
      }
    }
  },
  created() {
    this.getGoodsList()
  },
  methods: {
    // 初始化商品列表
    async getGoodsList() {
      const { data: res } = await this.$http.get('goods', {
        params: this.queryInfo
      })
      if (res.meta.status !== 200) {
        return this.$message.error('获取商品数据失败！')
      }
      this.goodsList = res.data.goods
      this.total = res.data.total
    },

  }
}
</script>

<style lang="less" scoped>
.add-user-btn { margin-left: 20px; }

</style>
